package com.dqhl.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.model.OrderParticulars;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.ViewHolder;

import org.xutils.x;

import java.util.List;

/**
 * Created by guanlucoang on 2016/9/21.
 */
public class OrderDetailAdapter extends BaseAdapter {

    private List<OrderParticulars> orderParticularses;
    private Context context;
    private LayoutInflater inflater;

    public OrderDetailAdapter(Context context, List<OrderParticulars> orderParticularses) {
        this.context = context;
        this.orderParticularses = orderParticularses;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return orderParticularses.size();
    }

    @Override
    public Object getItem(int i) {
        return orderParticularses.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.layout_item_orderdetailadapter, viewGroup, false);
        }
        ImageView iv_pic = ViewHolder.get(view, R.id.iv_pic);
        TextView tv_name = ViewHolder.get(view, R.id.tv_name);
        TextView tv_money = ViewHolder.get(view, R.id.tv_money);
        TextView tv_number = ViewHolder.get(view, R.id.tv_number);

        OrderParticulars orderParticulars = orderParticularses.get(i);

        x.image().bind(iv_pic, Config.Api.base_img_url + orderParticulars.getGoods_pic());
        tv_name.setText(orderParticulars.getName());
        tv_money.setText(orderParticulars.getPrice_one());
        tv_number.setText(orderParticulars.getNumber());

        return view;
    }
}
